const Express = require("express");
const SearchInfoServer = require('../../servers/SearchInfo');
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();



/**
 * 获取所有常用词库
 */
router.get("/getAllSearch",async(req,res)=>{
    try {
        const result = await SearchInfoServer.getAllSearch();
        ResponseHelper.sendData(result, res);
      } catch (err) {
        ResponseHelper.sendErr(err, res);
      }
})

/**
 * 获取所有常用符号
 */
router.get("/getAllSearchSymbol",async(req,res)=>{
    try {
        const result = await SearchInfoServer.getAllSearchSymbol();
        ResponseHelper.sendData(result, res);
    } catch (err) {
        ResponseHelper.sendErr(err, res);
    }
})

/**
 * 批量添加常用词库
 */
 router.post("/bulkCreateSearch", async (req, res) => {
    try {
      const result = await SearchInfoServer.bulkCreateSearch(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 拼音码搜索常用词库
 */
router.post("/getSearchByCode", async (req, res) => {
    try {
        console.log(req.body)
        const result = await SearchInfoServer.searchByPinyinOrCh(req.body.search);
        ResponseHelper.sendData(result, res);
    } catch (err) {
        console.log("err", err);
        ResponseHelper.sendErr(err, res);
    }
});


module.exports = router;
